package com.yss.sofa.report.engine.cell.visible.form;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.lang3.StringEscapeUtils;

import com.yss.sofa.report.engine.Const;
import com.yss.sofa.report.engine.cell.ReportCell;


public class DateFormCell extends FormCell{
	private static final long serialVersionUID = -6636362224467958410L;
	private String max;
	private String min;
	protected void init(){
		super.init();
		inputType=Const.FORM_INPUT_TYPE_DATE;
	}
	public void assignTo(ReportCell cell){
		DateFormCell _=(DateFormCell)cell;
		super.assignTo(_);
		_.max=this.max;
		_.min=this.min;
	}
	public DateFormCell create(){
		DateFormCell _=new DateFormCell();
		this.assignTo(_);
		return _;
	}
	public String getRenderSource() {
		return "date-field";
	}
	public String getMax() {
		return max;
	}
	public void setMax(String max) {
		this.max = max;
	}
	public String getMin() {
		return min;
	}
	public void setMin(String min) {
		this.min = min;
	}
	@Override
	public boolean isCustom() {
		return false;
	}
	@Override
	public String getJsValue(){
		if(value==null){
			return "'"+(new SimpleDateFormat("yyyy-MM-dd")).format(new Date())+"'";
		} else {
			return "'"+StringEscapeUtils.escapeEcmaScript(value)+"'";
		}
	}
	@Override
	public String getJsRaw(){
		return getJsValue();
	}
}
